package com.zx._12_算法.字节跳动面试题;

import com.zx._12_算法.Nums;
import java.util.HashMap;

/**
 * 思路1： 使用map
 * 思路2： 数组中，1<= nums[i] <=100，且不重复。可将 nums[i] 作为小标保存数据
 */
public class 数组两数之和为K的下标 {

    public static void main(String[] args) {
        int[] nums = Nums.nums;
        int k = 13;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
            Integer need = map.get(k - nums[i]);
            if (need != null) {
                System.out.println(need + "," + i);
                System.out.println(nums[need] + "," + nums[i]);
                break;
            }
        }
        Nums.print();
    }
}
